<?php
/**
 * Created by PhpStorm.
 * User: yzapple
 * Date: 2018/1/9
 * Time: 下午2:55
 */
namespace app\common\model;
use app\common\model\Base;
use think\Db;

class Feedback extends Base
{
    protected $table = "feedback";
    protected $base_arr = [
        'table' => 'feedback',
        'field' => 'id,is_read',
        'primary_key' => 'id'
    ];

    protected $attach_arr =  [


    ];

    /**
     * 获取字段对应的数组
     * */
    public function getDataByMysql(){
        $data = [
            't_name' => $this->table,//必填
            'model' => '反馈',//必填
            'id'=>'记录',
            'is_read' => '{"1":"变为已读","0":"未读"}',


        ];
        return $data;
    }


    /**
     * 获取日志的访问方法
     **/
    public static function getFeedbackAdminLog($list_action='',$form_data=[],$userId,$admin_type){
        $model = new Feedback();
        $actionName = strtolower(ACTION_NAME);
        $controller = strtolower(CONTROLLER_NAME);
        $old_data = [];
        $type = '';

        switch($actionName){
            //列表
            case "notes":
                Base::save_admin_log($userId, $model, 'check','',[],[],$admin_type);
                break;
            case "notes_detail":
                $type = 'detail';
                $record_data['id'] = $form_data['fid'];
                $form_data = DB::name($model->table)
                    ->field($model->base_arr['field'])
                    ->where($record_data)->find();
                $form_data['id'] = $record_data['id'];
                if($form_data['is_read']==0){
                    DB::name($model->table)
                        ->where($record_data)->update(['is_read'=>1,'update_time'=>date('Y-m-d h:s:i')]);
                    $form_data['is_read'] = 1;

                }else{
                    unset( $form_data['is_read']);
                }

                break;

        }

        $result = true;

        if($model->request->isPost()){

            //$model 实例化之后的模型
            //$type 数据的操作类型
            //$form_data  form表单提交之后的表单
            //$url 跳转路径
            //$old_data 原有的数据
            //$attach_arr 附属表单数组
            //$primary_key 基本表单的主键值id

            $result =  Base::operaTable($model,$userId,$type,$form_data,$controller.'/'.$list_action,$old_data,$model->attach_arr,'id',$admin_type);
        }
        else if($type == 'detail'){

            $result =  Base::operaTable($model,$userId,$type,$form_data,'',$old_data,$model->attach_arr,'id',$admin_type,false);
        }

        return $result;


    }

}